package com.gitee.wsl.doc.sample.rss


import com.gitee.wsl.doc.xml.XmlPullParserException
import com.gitee.wsl.doc.xml.XmlPullParserFactory
import kotlinx.io.IOException


object ParseRSS : com.gitee.wsl.doc.sample.rss.ParseRSSOperation {

    private var factory: XmlPullParserFactory? = XmlPullParserFactory

    /**
     * ParseRSS Initialization. Call this method once on application start
     */
    fun init(pullParserFactory: XmlPullParserFactory) {
        factory = pullParserFactory
    }

    override fun release() {
        factory = null
    }

    /**
     * RSS Feed constructor function for generic RSSFeed object
     */
//    @Deprecated("unused", ReplaceWith(""), DeprecationLevel.ERROR)
//    override var applyRSSFeedConstructor: (() -> RSSFeed) = { RSSFeedObject() }

//    @Suppress("UNCHECKED_CAST")
//    @Throws(XmlPullParserException::class, IOException::class, ParseRSSException::class)
//    override fun <R : RSSFeed> parse(xml: Reader): R {
//        return parse(xml, false) {
//            RSSFeedObject()
//        } as R
//    }

    @Suppress("UNCHECKED_CAST")
    @Throws(XmlPullParserException::class, IOException::class, _root_ide_package_.com.gitee.wsl.doc.sample.rss.ParseRSSException::class)
    override fun <R : com.gitee.wsl.doc.sample.rss.RSSFeed> parse(xml: String): R {
        return parse(xml, false) {
            _root_ide_package_.com.gitee.wsl.doc.sample.rss.RSSFeedObject()
        } as R
    }

    override fun <T : com.gitee.wsl.doc.sample.rss.RSSFeed> parse(xml: String, strictlyNamespaceChecking: Boolean, feedSupplier: () -> T): T {
        val unwrappedFactory = factory ?: throw _root_ide_package_.com.gitee.wsl.doc.sample.rss.ParseRSSException("xmlPullParserFactory is null. Should call ParseRSS.init() once.")
        return _root_ide_package_.com.gitee.wsl.doc.sample.rss.ParserExecutor(
            unwrappedFactory,
            xml,
            strictlyNamespaceChecking,
            feedSupplier
        ).run()
    }
}
